package com.gomore.opple.module.addressdialog;

import android.os.Bundle;
import android.view.KeyEvent;

import com.gomore.opple.R;
import com.gomore.opple.module.BaseActivity;
import com.gomore.opple.module.IntentStart;

import javax.inject.Inject;

/**
 * Created by asus on 2017/5/9.
 */
public class AddressDialogActivity extends BaseActivity {
    @Inject
    AddressDialogPresenter addressDialogPresenter;

    private AddressDialogFragment addressDialogFragment;
    private String storeCode;

    @Override
    protected void initalizeViewData() {
        super.initalizeViewData();
        this.setFinishOnTouchOutside(false);
        if (getIntent() != null && getIntent().getStringExtra(IntentStart.STORECODE) != null) {
            storeCode = getIntent().getStringExtra(IntentStart.STORECODE);
        }
    }

    @Override
    protected void initalizeViews() {
        if (addressDialogFragment == null) {
            addressDialogFragment = AddressDialogFragment.getInstance();
            Bundle bundle = new Bundle();
            bundle.putString(IntentStart.STORECODE, storeCode);
            addressDialogFragment.setArguments(bundle);
            replaceFragment(addressDialogFragment, false, "address_dialog_view");
        }
    }

    @Override
    protected void initializeDependencyInjector() {
        DaggerAddressDialogComponent.builder()
                .dataRepositoryComponent(getRepositoryComponent())
                .addressDialogModule(new AddressDialogModule(addressDialogFragment))
                .build()
                .inject(this);
    }

    @Override
    protected int getLayoutView() {
        return R.layout.activity_address_dialog;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
